package 共享单车;

import org.apache.hadoop.io.NullWritable;
import org.apache.hadoop.mapreduce.RecordWriter;
import org.apache.hadoop.mapreduce.TaskAttemptContext;

import java.io.BufferedWriter;
import java.io.FileWriter;
import java.io.IOException;

public class MyRecordWriter extends RecordWriter<JavaBean, NullWritable> {
    BufferedWriter bw;

    public MyRecordWriter(TaskAttemptContext taskAttemptContext) {

    }

    public void write(JavaBean key, NullWritable value) throws IOException, InterruptedException {
        String city = key.getCity();
        String path = "D:\\MP\\共享单车\\output1\\" + city + ".txt";
        bw = new BufferedWriter(new FileWriter(path, true));
        bw.write(key.toString());
        bw.write("\n");
        bw.flush();
    }

    public void close(TaskAttemptContext context) throws IOException, InterruptedException {
        bw.close();
    }
}
